﻿
settings = window.settings || [];
settings.destinationHost = settings.destinationHost === window.location.origin ? settings.destinationHost : window.location.origin;

const ClosedPageIDCookieName = "b2b_flbar_close_page_s";
const ClosedFloatingButtonPageIDCookieName = "b2b_flbtn_close_page_s";
const ClosedPainPointPageIDCookieName = "b2b_painpoint_close_page_s";
window.CloseFloatingBannerPageIDCookieName = "b2b_flbnr_close_page_s";
var B2BFormCookieName = "b2b_form_cookie";
$(document).ready(function () {

	var popup = DemoHelper.GetQueryString('popup');
	const objKeyValueInUrlParams = { price: 'ca', survey: 'survey', 'pay-equity': 'pe', 'job-description': 'jd', free: 'freetrial14d', petrial: 'pe' };
	const objKey = Object.keys(objKeyValueInUrlParams).find(key => popup === key);
	if (objKey) {
		var desc = DemoHelper.GetQueryString('desc'); // this field determins the lead source, only used for pe which come from gateway top nav 
		desc = popup.toLocaleLowerCase() === "free" ? objKeyValueInUrlParams[objKey] : desc;
		getB2BPopupEntryJS(ClickPositionType.OuterLink, DemoFormPopupType.Click, desc, objKeyValueInUrlParams[objKey]);
	}
	else {
		getB2BPopupEntryJS(ClickPositionType.None, DemoFormPopupType.Auto, "", DemoType.None);  // all the page will execute this line, and which demo type will popup depends on server.
	}

	clickCTAPopupInquiryDemoOnTopNav();

	clickCTAPopupRequestDemoOnMobile();  // see it action button in hero/footer on mobile 

});

const getB2BPopupEntryJS = (_clickPositionType, _popupType, _ctaText, _demoType, _productType, _isCPLandingPage = false) => {
	_demoType = _demoType || DemoType.None;
	popupType = _popupType;
	_productType = _productType || ProductType.None;
	_clickPositionType = _clickPositionType || ClickPositionType.None;
	_ctaText = _ctaText || "";
	_isCPLandingPage = _isCPLandingPage;
    let demoFormTargetUrl = [`${settings.destinationHost}/business/`, `${settings.destinationHost}/companalyst/`, `${settings.destinationHost}/blog/`,
    `${settings.destinationHost}/resources/`, `${settings.destinationHost}/pay-equity/`, `${settings.destinationHost}/`];
    const url = window.location.href;// _popupType == "auto" ? window.location.href : window.location.href.split(/[?#]/)[0];

    if (demoFormTargetUrl.filter((i) => url.includes(i)).length !== 0 || url === `${settings.destinationHost}/`) {
        if (_popupType === DemoFormPopupType.Click && B2BPopupProgress.ClickPopupStart) return;
        if (_popupType === DemoFormPopupType.Click && !B2BPopupProgress.ClickPopupStart) {
            B2BPopupProgress.ClickPopupStart = true;
            B2BPopupProgress.ClickPopupEnd = false;
        }
        if (_popupType === DemoFormPopupType.Auto && B2BPopupProgress.ClickPopupStart) return;
        if (_popupType === DemoFormPopupType.Auto) {
            B2BPopupProgress.AutoPopupStart = true;
            B2BPopupProgress.AutoPopupEnd = false;
        }
        const params = { strUrl: url, bClickPositionType: _clickPositionType, strPopupTypeDesc: _popupType, strDemoFormTypeDesc: _demoType, bProductType: _productType, strCTAText: _ctaText, bolIsCPLandingPage: _isCPLandingPage };
        var com = new CommunicationManager();
        com.invokeInquiryAndFloatingBarDemoPopupEntry(params, function (script) {
            if (script) {
                appendEmbeddedEntryJSCode(script, 'entryjs');
            }
            else {  // means current page doesn't support display floating button 
                resetB2BPopuProgress();
            }
        });
    }

};

const autoPopupPainPointsDemoOnDesktopForProductPage = () => {
	const params = { strUrl: window.location.href.toLowerCase() };
	var com = new CommunicationManager();
	com.invokePainpointsDemoForProductPagePopupEntry(params, function (script) {
		if (script) {
			appendEmbeddedEntryJSCode(script, 'painpointsEntryJS');
		}
	});

};

// cta button(popup pe/ja.etc. form) on top nav
const clickCTAPopupInquiryDemoOnTopNav = (_demoType, _productType) => {
	const arrCTAButtonClass = ["sa_topnav_btn_cta", "sa_home_topnav_btn_cta"];
	arrCTAButtonClass.forEach(ele => {
		let ctaButtonEle = document.getElementById(ele);
		if (ctaButtonEle !== null) {
			ctaButtonEle.addEventListener('click', (event) => {
				let demoForm = document.getElementById('sal-demoform-container');
				if (demoForm !== null) { demoForm.remove(); }
				let ctaText = ctaButtonEle.firstChild.innerHTML.toLowerCase().trim();
				let clickPositionType = ClickPositionType.None;
				let productType = ProductType.None;
				let demoType = DemoType.None;
				switch (ele) {
					case 'sa_topnav_btn_cta':
						clickPositionType = ClickPositionType.TopNavMenu;
						break;
					case 'sa_home_topnav_btn_cta':
						clickPositionType = ClickPositionType.TopNavGateway;
						break;
				}
				if (clickPositionType === ClickPositionType.TopNavGateway && ctaText.includes('pay equity')) {
					return;
				}
				event.preventDefault();
				if (ctaText.includes('pay equity')) {
					productType = ProductType.PE;
					demoType = DemoType.PE;
				} else if (ctaText.includes('job desc.')) {
					productType = ProductType.JA;
					demoType = DemoType.JD;
				} else if (ctaText.includes('price a job')) {
					productType = ProductType.CA;
					demoType = DemoType.CA;
				}
				getB2BPopupEntryJS(clickPositionType, DemoFormPopupType.Click, ctaText, demoType, productType);
			});
		}
	});
};

// see it action button in hero/footer on mobile for product page 
const clickCTAPopupRequestDemoOnMobile = () => {
	if (isMobileMenu) {
		const arrCTAButtonID = ["sa-m-sticky-demo", 'sa_topnav_cta_demo', "sa_hero_cta_demo", "sa_footer_cta_demo"];

		arrCTAButtonID.forEach(ele => {
			let ctaButtonEle = document.getElementById(ele);
			ctaButtonEle && ctaButtonEle.addEventListener('click', (event) => {
				var url = getCurrentStandarizdUrl();
				if (url.indexOf("/business/compensation-data/daas/") > -1) {
					return;
				}
				//if (arrProductPageUrl.find(q => q.toLowerCase() === url) === undefined)
				//    return;

				event.preventDefault();
				let demoForm = document.getElementById('sal-requestdemoform-container');
				if (demoForm !== null) { demoForm.remove(); }

				let ctaText = null;
				let clickPositionType = ClickPositionType.None;
				if (ctaButtonEle.childElementCount !== 0)
					ctaText = ctaButtonEle.firstElementChild.textContent.toLowerCase().trim();
				else
					ctaText = ctaButtonEle.textContent.trim().toLowerCase();
				switch (ele) {
					case 'sa-m-sticky-demo':
						clickPositionType = ClickPositionType.StickyDemoOnMobileTopNav;
						break;
					case 'sa_topnav_cta_demo':
						clickPositionType = ClickPositionType.RequestADemoOnTopNav;
						break;
					case 'sa_hero_cta_demo':
						clickPositionType = ClickPositionType.SeeItActionHero;
						break;
					case 'sa_footer_cta_demo':
						clickPositionType = ClickPositionType.SeeItActionFooter;
						break;
				}
				// must passed non demotype.none such as DemoType.CA, but don't use it in backend as final demo type show.
				getB2BPopupEntryJS(clickPositionType, DemoFormPopupType.Click, ctaText, DemoType.CA, ProductType.None);
			});
		});
	}

};


const appendEmbeddedEntryJSCode = (script, scriptId) => {
	var head = document.getElementsByTagName('head')[0];
	var tag = document.createElement('script');
	tag.type = 'text/javascript';
	tag.id = `${scriptId}`;
	var inlineScript = document.createTextNode(script.replace('<script>', '').replace('</script>', ''));
	tag.appendChild(inlineScript);
	var script = document.getElementById(scriptId);
	if (script !== null) {
		head.removeChild(script);
	}
	head.appendChild(tag);
};

const getCurrentStandarizdUrl = function () {
	var url = window.location.pathname.toLowerCase();
	if (!url.endsWith('/'))
		url = `${url}/`;
	return url;
};

const resetB2BPopuProgress = function () {
	B2BPopupProgress.AutoPopupStart = false;
	B2BPopupProgress.AutoPopupEnd = false;
	B2BPopupProgress.ClickPopupStart = false;
	B2BPopupProgress.ClickPopupEnd = false;
};
var popupType;
var demoType;

var B2BPopupProgress = {
	AutoPopupStart: false,
	AutoPopupEnd: false,
	ClickPopupStart: false,
	ClickPopupEnd: false
};

var DemoType = {
	None: 'none',
	CA: 'ca',
	Survey: 'survey',
	JD: 'jd',
	PE: 'pe',
	Consulting: 'consulting',
	CP: 'cp',
	IQ: 'iq',
	JSM: 'jsm'
};

var DemoFormPopupType = {
	Auto: 'auto',
	Click: 'click'
};

var PageCategoryType =
{
	None: 0,
	CA: 1,
	PayEquity: 2,
	JA: 3,
	CAMD: 4,
	Survey: 5,
	JSM: 7,
	CP: 9,
	IQ:11
}

var ProductType =
{
	None: 0,
	JA: 1 << 0,
	CA: 1 << 1,
	IPAS: 1 << 4,
	CompData: 1 << 5,
	CAMD: 1 << 3,
	CompData: 1 << 5,
	PE: 1 << 6,
	Consulting: 1 << 7,
	JSM: 7,
	CP: 9,
	Rewards: 10,
	IQ:11,
	All: 115
}

var ClickPositionType =
{
	None: 0,
	OuterLink: 1,
	TopNavMenu: 2,
	TopNavGateway: 3,
	InContent: 4,
	SeeItActionHero: 5,
	SeeItActionFooter: 6,
	StickyDemoOnMobileTopNav: 7,
	RequestADemoOnTopNav: 8,
	InBlogContent: 9,
	SideBar: 10
}

var CommunicationManager = function () {
	this.baseApi = "/business/search/{controller}/{action}";
};

CommunicationManager.prototype = function () {
	var resolveApiUrl = function (action) {
		return this.baseApi
			.replace("{controller}", "BusinessSearch")
			.replace("{action}", action);
	},
		handleCommunicationError = function (ex) { },
		executeWebApiAction = function (requestMethod, action, callbackSuccess, callbackError, postData, dataType, isAsync) {
			var that = this,
				ajaxRequest = null,
				url = resolveApiUrl.call(this, action),
				successCallback = function (data) {
					callbackSuccess(data);
				},
				failCallback = function (data) {
					if (callbackError == undefined) {
						callbackError = function (ex) {
							handleCommunicationError.call(that, ex);
						};
					}
					callbackError(data);
				};

			if (requestMethod === "POST") {
				let ajaxOptions = {
					type: "POST",
					url: url,
					data: postData,
					async: (isAsync != null && isAsync === false) ? false : true
				};
				if (dataType) ajaxOptions.dataType = dataType;
				ajaxRequest = $.ajax(ajaxOptions)
					.done(successCallback)
					.fail(failCallback);
			}

			return ajaxRequest;
		},

		post = function (action, data, dataType, callbackSuccess, callbackError, isAsync) {
			var ajaxRequest = executeWebApiAction.call(this, "POST", action, callbackSuccess, callbackError, data, dataType, isAsync);
			return ajaxRequest;
		},
		invokeInquiryAndFloatingBarDemoPopupEntry = function (data, callbackSuccess, callbackError) {
			post.call(this, "SalAjxPopupEntry", data, null, callbackSuccess, callbackError);
		},
		invokeFloatingButtonPopupEntry = function (data, callbackSuccess, callbackError) {
			post.call(this, "SalAjxFloatingButtonPopupEntry", data, null, callbackSuccess, callbackError);
		},
		invokeInquiryDemoButtonOnDesktopForPodcastListPagePopupEntry = function (data, callbackSuccess, callbackError) {
			post.call(this, "SalAjxInquiryDemoButtonOnDesktopForPodcastListPagePopupEntry", data, null, callbackSuccess, callbackError);
		},
		invokePainpointsDemoForProductPagePopupEntry = function (data, callbackSuccess, callbackError) {
			post.call(this, "SalAjxPainPointsDemoForProductPagePopupEntry", data, null, callbackSuccess, callbackError);
		},
		invokeInquiryDemoForPodcastDetailPagePopupEntry = function (data, callbackSuccess, callbackError) {
			post.call(this, "SalAjxInquiryDemoForPodcastDetailPagePopupEntry", data, null, callbackSuccess, callbackError);
		},
		invokeInquiryJobSkillsDemoPopupEntry = function (data, callbackSuccess, callbackError) {
			post.call(this, "SalAjxJobSkillDemoPopupEntry", data, null, callbackSuccess, callbackError);
		},
		invokePromoBannerDemoPopupEntry = function (data, callbackSuccess, callbackError) {
			post.call(this, "SalAjxPromoBannerEntry", data, null, callbackSuccess, callbackError);
		};
	return {
		post: post,
		invokeInquiryAndFloatingBarDemoPopupEntry: invokeInquiryAndFloatingBarDemoPopupEntry,
		invokeFloatingButtonPopupEntry: invokeFloatingButtonPopupEntry,
		invokeInquiryDemoButtonOnDesktopForPodcastListPagePopupEntry: invokeInquiryDemoButtonOnDesktopForPodcastListPagePopupEntry,
		invokeInquiryDemoForPodcastDetailPagePopupEntry: invokeInquiryDemoForPodcastDetailPagePopupEntry,
		invokePainpointsDemoForProductPagePopupEntry: invokePainpointsDemoForProductPagePopupEntry,
		invokeInquiryJobSkillsDemoPopupEntry: invokeInquiryJobSkillsDemoPopupEntry,
		invokePromoBannerDemoPopupEntry: invokePromoBannerDemoPopupEntry
	};
}();

var DemoHelper = (function ($) {
	return {
		UpdateUrlParameter: function (url, key, value) {
			//url = window.top.location.href;
			url = url.split('#')[0];
			var re = new RegExp("([?&])" + key + "=.*?(&|#|$)(.*)", "gi"),
				hash;

			if (re.test(url)) {
				if (typeof value !== 'undefined' && value !== null)
					return url.replace(re, '$1' + key + "=" + value + '$2$3');
				else {
					hash = url.split('#');
					url = hash[0].replace(re, '$1$3').replace(/(&|\?)$/, '');
					if (typeof hash[1] !== 'undefined' && hash[1] !== null)
						url += '#' + hash[1];
					return url;
				}
			}
			else {
				if (typeof value !== 'undefined' && value !== null) {
					var separator = url.indexOf('?') !== -1 ? '&' : '?';
					hash = url.split('#');
					url = hash[0] + separator + key + '=' + value;
					if (typeof hash[1] !== 'undefined' && hash[1] !== null)
						url += '#' + hash[1];
					return url;
				}
				else
					return url;
			}
		},
		GetQueryString: function (key, url) {
			url = url || window.top.location.href;
			var regex = new RegExp("[?&]" + key + "(=([^&#]*)|&|#|$)", "i"), results = regex.exec(url);

			if (!results) {
				if (console) {
					//console.log('returning null for ' + key + ' and ' + url);
				}
				return null;
			}

			if (!results[2]) {
				if (console) {
					//console.log('returning empty for ' + key + ' and ' + url);
				}
				return '';
			}

			return decodeURIComponent(results[2].replace(/\+/g, " "));
		},
		setItem: function (key, value, ttl) {
			let item = {
				value: value,
				expiry: !!ttl ? ttl : (Date.now() + 90 * 24 * 60 * 60 * 1000)
			};
			localStorage.setItem(key, JSON.stringify(item));
		},
		getItem: function (key) {
			let item = localStorage.getItem(key);
			if (!item) return null;
			if (item.expiry && Date.now() > item.expiry) {
				localStorage.removeItem(key);
				return null;
			}
			item = JSON.parse(item);
			return item.value;
		},
		getCookie: function (cname) {
			var name = cname + "=";
			var ca = top.document.cookie.split(";");
			for (var i = 0; i < ca.length; i++) {
				var c = ca[i];
				while (c.charAt(0) == " ") c = c.substring(1);
				if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
			}
			return "";
		},
		setCookie: function (cname, cvalue, exdays) {
			exdays = exdays || -1;
			if (exdays === -1) {
				top.document.cookie = cname + "=" + cvalue + "; path=/";
				return;
			}
			var d = new Date();
			d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
			var expires = "expires=" + d.toUTCString();
			top.document.cookie = cname + "=" + cvalue + "; " + expires + ";path=/";
		},
		GetProductTypeString: function (id) {
			switch (id) {
				case 0:
					return "None";
				case 1:
					return "JA";
				case 2:
					return "CA";
				case 8:
					return "CAMD";
				case 9:
					return "CP";
				case 16:
					return "IPAS";
				case 32:
					return "CompData";
				case 64:
					return "PE";
				case 128:
					return "Consulting";
				case 115:
					return "All";
				default:
					return "N/A";
			}
		},
		GetPageCategoryTypeString: function (id) {
			switch (id) {
				case 0:
					return "None";
				case 1:
					return "CA";
				case 2:
					return "PayEquity";
				case 3:
					return "JA";
				case 4:
					return "CAMD";
				case 5:
					return "Survey";
				case 6:
					return "Resources";
				case 7:
					return "Blog";
				case 8:
					return "CaseStudy";
				case 9:
					return "ProductSheet";
				case 10:
					return "eBook";
				case 11:
					return "Guide";
				case 12:
					return "Infographic";
				case 13:
					return "KeyTakeaway";
				case 14:
					return "Podcast";
				case 15:
					return "Video";
				case 16:
					return "Webinar";
				case 17:
					return "WhitePaper";
				case 18:
					return "SurveySummary";
				case 19:
					return "HowTo";
				case 20:
					return "Webcast";
				case 21:
					return "Presentation";
				case 25:
					return "CP";
				case 32:
					return "ResourcesMainPage";
				default:
					return "N/A";
			}
		},
		GetProductTypeNum: function (strProductType) {
			strProductType = strProductType || "none";
			switch (strProductType.toLowerCase()) {
				case "ca":
					return ProductType.CA;
				case "camd":
					return ProductType.CAMD;
				case "pe":
					return ProductType.PE;
				case "compdata":
					return ProductType.CompData;
				case "ipas":
					return ProductType.IPAS;
				case "ja":
					return ProductType.JA;
				case "consulting":
					return ProductType.Consulting;
			}
		},
		GetDemoTypeStringByProductType: function (numProductType) {
			if (typeof numProductType !== 'number')
				throw new TypeError('numProductType must be a number type.', "Seou_Share_Popup_Entry.js")
			switch (numProductType) {
				case ProductType.CA:
				case ProductType.CAMD:
					return DemoType.CA;
				case ProductType.CompData:
				case ProductType.IPAS:
					return DemoType.Survey;
				case ProductType.JA:
					return DemoType.JD;
				case ProductType.PE:
					return DemoType.PE;
				case ProductType.Consulting:
					return DemoType.Consulting;
			}
		},
		NewGuid: function () {
			return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,
				function (c) {
					var r = Math.random() * 16 | 0,
						v = c == 'x' ? r : (r & 0x3 | 0x8);
					return v.toString(16);
				}).toUpperCase();
		},
		IsValidPhoneNumber: function (isUSA = false, isCAN = false, val = "") {
			var isvalid = false;
			var reg = "";
			if (isUSA) {
				reg = /^[0-9-\(\)]{1,13}$/;
				isvalid = reg.test(val);
				if (!isvalid) {
					reg = /[\+]*([1 -])*[(]?[\d]{3,3}[- \.)]*[\d]{3,3}[- \.]*[\d]{2,4}[/-]?([\d]{2,4})/;
					isvalid = reg.test(val);
				}
			}
			else if (isCAN) {
				reg = /^[0-9-\(\)]{1,13}$/;
				isvalid = reg.test(val);
			} else {
				reg = /^[a-zA-Z0-9-\(\)]*$/;
				isvalid = reg.test(val);
			}
			return isvalid;
		},
		Equal: function (text, other) {
			return text.localeCompare(other, undefined, { sensitivity: 'base' }) === 0;
		},
		HtmlDecode: function (input) {
			var doc = new DOMParser().parseFromString(input, "text/html");
			return doc.documentElement.textContent;
		},
		GetPageUrl: function () {
			var url = this.HtmlDecode(window.top.location.href);// pageUrl.split(/[?#]/)[0];
			if (!this.GetQueryString('force_debug')) {
				var objQaDebug = this.getItem('b2b_debug');
				if (objQaDebug !== null) {
					url = this.UpdateUrlParameter(url, 'force_debug', objQaDebug.force_debug);
					if (!this.GetQueryString('send_to')) {
						url = this.UpdateUrlParameter(url, 'send_to', objQaDebug.send_to);
					}
				}
			}
			return url;
		},
		GetCurrenCookietLimitSubmit: function (classname) {
			let isValid = true;
			var currenCookietLimitSubmit = Helper.getCookie("b2b_scheduledemo_submitdate_new");
			if (currenCookietLimitSubmit != "") {
				const cookieList = currenCookietLimitSubmit.split("&")[0].split("=");
				var currentCookieSubmitDate = cookieList[1];
				$('.' + classname + ' .submitcurrentmeetingdate').text(currentCookieSubmitDate);
				$('.' + classname + ' #schedule_modal-warning').css("display", "block");
				//const element = $('#schedule_modal-warning')[0];
				//const yOffset = -10;
				//const y = element.getBoundingClientRect().top + window.pageYOffset + yOffset;
				$('.' + classname + '').animate({ scrollTop: 0 }, 500);
				isValid = false;
			}
			return isValid;
		},
		IsCompanyEmail: function (emailAddress) {
			emailAddress = emailAddress || "";
			const excludeEmailList = ['Gmail.com', 'Hotmail.com', 'yahoo.com', 'qq.com', '163.com', 'iCloud.com', 'outlook.com'];
			let isExclude = excludeEmailList.map(m => emailAddress.toLowerCase().indexOf(m.toLowerCase())).filter(q => q !== -1).length > 0;
			if (isExclude) {

				return false;
			}
			return true;
		},
		IsPC: function () {
			var userAgentInfo = navigator.userAgent;
			var Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod");
			var flag = true;
			for (var v = 0; v < Agents.length; v++) {
				if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = false; break; }
			}
			return flag;
		}
	};
})(jQuery);

function inquiryFormCookieInit() {
	let b2b_form_cookie = DemoHelper.getItem("b2b_form_cookie");
	let value;
	let $target;
	if (b2b_form_cookie != null) {
		for (var field in b2b_form_cookie) {
			value = b2b_form_cookie[field];
			field = field.toLowerCase() === "fte" ? "number" : field;
			field = field.toLowerCase() === "countrycode" ? "country" : field;
			field = field.toLowerCase() === "statecode" ? "state" : field;
			field = field.toLowerCase() === "workemail" ? "email" : field;
			field = field.toLowerCase() === "isconsentdatacollection" ? "consent-collection" : field;
			field = field.toLowerCase() === "isconsentprivacypolicy" ? "consent-pp" : field;
			$target = $("[id$='demoform-" + field.toLowerCase() + "']");
			if ($target.length == 0) {
				$target = $("[id$='demoform_howto-" + field.toLowerCase() + "']");
			}
			if ($target.length > 0) {
				$target.val(value);
				if (field === "state") {
					if ($("[id$='state-options']").length > 0) {
						$("[id$='state-options'] .sal-custom-option[data-statecode='" + value + "']").trigger("click");
						$("[id$='state-wrapper']").trigger("click");
					}
				}
				if (field === "country") {
					if ($("[id$='country-options']").length > 0) {
						$("[id$='country-options'] .sal-custom-option[data-countrycode='" + value + "']").trigger("click");
						$("[id$='country-wrapper']").trigger("click");
					}
					if (b2b_form_cookie.hasOwnProperty("statecode")) {
						value = b2b_form_cookie["statecode"];
						if ($("[id$='state-options']").length > 0) {
							$("[id$='state-options'] .sal-custom-option[data-statecode='" + value + "']").trigger("click");
							$("[id$='state-wrapper']").trigger("click");
						}
					}
				}
				if ((field === "consent-collection" || field === "consent-pp") && value == 1) {
					$target.closest(".consent-div").trigger("click");
				}
				if (field === "number") {
					if ($("[id$='number-options']").length > 0) {
						if (Number(value) < 250) {
							$("[id$='number-options'] .sal-custom-option:eq(0)").trigger("click");
						} else {
							$("[id$='number-options'] .sal-custom-option:eq(1)").trigger("click");
						}
						$("[id$='number-wrapper']").trigger("click");
					}
				}
			}
		}
	}

}

const arrStoragePropertyName = [
	'strCurrentJobTitle',
	'strFirstName',
	'strLastName',
	'strWorkEmail',
	'strFTE',
	'strCompanyName',
	'strPhoneNumber',
	'strCountryCode',
	'strStateCode',
	'intIsConsentDataCollection',
	'intIsConsentPrivacyPolicy'
];

function setInquiryFormCookie(dataParams) {
	try {
		dataParams = dataParams || {};
		let b2b_form_cookie = DemoHelper.getItem("b2b_form_cookie");
		if (b2b_form_cookie == null) {
			b2b_form_cookie = {};
		}

		for (var prop in dataParams) {
			if (dataParams[prop] != "" && arrStoragePropertyName.find(q => q == prop)) {
				b2b_form_cookie[prop.substr(3).toLowerCase()] = dataParams[prop];
			}
		}

		if ('strStateCode' in dataParams && 'strCountryCode' in dataParams && dataParams.strStateCode === "") {
			delete b2b_form_cookie.statecode;
			if (dataParams.strCountryCode === "USA")
				delete b2b_form_cookie.countrycode;
		}

		DemoHelper.setItem("b2b_form_cookie", b2b_form_cookie);
	} catch (ex) {
		console.error(ex);
	}
}

function btnCloseWaringFormModal(obj) {
	obj.parentElement.parentElement.style.display = 'none'
}

